<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-07-30 20:02:30
 * @LastEditTime: 2020-02-28 11:25:38
 * @LastEditors: Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../css/base.css" />
    <link rel="stylesheet" href="../css/elementui.css">
    <script type="text/javascript" src="../script/jquery.js"></script>
    <script type="text/javascript" src="../script/layer/mobile/layer.js"></script>
    <script type="text/javascript" src="../script/vue.min.js"></script>
    <script type="text/javascript" src="../script/vant.min.js"></script>
    <script type="text/javascript" src="../script/fastclick.js"></script>
    <script type="text/javascript" src="../script/base.js"></script>
    <script src="../script/elementui.js"></script>
    <style>
        .box {
            width: 100%;
            display: flex;
            flex-direction: column;
        }

        .form {
            width: 100%;
            height: auto;
        }

        .content {
            padding: 0 50px;
        }

        .van-field {
            width: 33.33%;
            float: left;
        }

        .van-cell {
            background-color: transparent;
        }

        .van-field__control {
            border-bottom: 2px solid #e6c678;
        }

        .van-cell::after {
            border-bottom: 0;
        }

        .van-cell {
            background-color: transparent;
        }

        .van-cell::after {
            border-bottom: 0;
        }

        .head .van-row .van-col,
        .content .van-row .van-col {
            margin-bottom: 8px;
            text-align: center;
            font-weight: 300;
            color: #e6c678;
            font-size: 14px;
        }

        .content .van-row .van-col .van-field {
            padding: 0;
            background: #fff;
            border: 1px solid #cecece;
            border-radius: 5px;
        }

        .content .van-row .van-col .van-field__control {
            color: #000;
        }

        @keyframes load {
            0% {
                box-shadow: inset 0px 0px 100px 10px rgba(61, 134, 208, 0.6);
            }

            100% {
                box-shadow: inset 0px 0px 20px 10px rgba(61, 134, 208, 0.1);
            }
        }

        .green {
            color: green;
        }

        .red {
            color: red;
        }

        .yellow {
            color: yellow;
        }

        .right-button .van-button {
            margin-left: 5px;
            min-width: 100px;
        }

        .scanImg img {
            width: 40px;
            height: 40px;
        }

        .devicePop {
            height: 50%;
            overflow: auto;
        }

        .devicePop .van-col {
            padding: 5px 8px;
            text-align: center;
        }

        .devicePop .van-col .van-button {
            width: 100%;
        }

        .devicePop .van-col .van-button .van-button__text {
            color: #090909;
        }

        .scanPop {
            width: 160px;
            height: 180px;
            text-align: center;
            background-color: transparent;
            margin: 0;
            padding: 0;
        }

        .van-icon-enlarge {
            font-size: 150px;
            color: #e6c678;
            margin: 0;
            padding: 0;
        }

        .inputClass {
            opacity: 0;
            width: 150px;
        }

        .scanLine {
            position: absolute;
            z-index: 2;
            width: 66%;
            height: 2px;
            transform: translateX(25%);
            background-color: #e6c678;
            animation: scanLineMove 2s infinite;
        }

        .newClass {
            color: red;
        }

        @keyframes scanLineMove {
            from {
                top: 30px;
            }

            to {
                top: 120px;
            }
        }

        .el-radio.is-bordered.is-checked {
            border-color: #e6c678;
        }

        .el-radio__input.is-checked .el-radio__inner {
            border-color: #e6c678;
            background: #e6c678;
        }

        .el-radio__input.is-checked+.el-radio__label {
            color: #e6c678;
        }

        .topLeft {
            width: 50%;
            padding-left: 5px;
        }

        .top .van-button {
            margin-top: 10px;
            margin-left: 5px;
            padding: 10px 20px;
        }

        .el-radio__label {
            color: #fff;
        }

        .box .content .table .van-field {
            width: 100%;
            /* border: 1px solid #808080; */
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="box">
            <div class="top">
                <div class="topLeft">
                    <van-button size="small" color="linear-gradient(#fffeaa, #c07d39)" type="primary"
                        @click="onClickLeft">返回</van-button>
                </div>
                <div class="topRight">
                </div>
            </div>

            <div class="content">
                <div class="form">
                    <van-field v-model="formData.BillNO" label="维修编号：" readonly></van-field>
                    <van-field v-model="formData.EquipmentName" label="机台：" readonly @click="openBaseScreen('机台')">
                    </van-field>
                    <van-field v-model="formData.repairName" label="维修人员：" readonly></van-field>
                    <van-field v-model="formData.WXStartTime" label="维修时间：" readonly></van-field>
                    <van-field v-model="formData.BXContent" label="设备故障描述：" readonly>
                    </van-field>
                </div>
                <div class="table">
                    <van-field v-model="formData.Reason" label="原因分析："></van-field>
                    <van-field v-model="formData.GZCause" label="维修内容："></van-field>
                    <van-field v-model="formData.DesRepContent" label="更换零部件描述："></van-field>
                </div>
            </div>

            <div class="bottom">
                <div class="left-content">
                </div>
                <div class="right-button flex-box">
                    <van-button color="#e6c678" @click="confirmSub" block>{{formData.WXStartTime ? '结束维修' : '开始维修'}}
                    </van-button>
                </div>
            </div>
        </div>

        <van-popup v-model="scanShow" class="scanPop">
            <div class="scanLine"></div>
            <van-icon name="enlarge"></van-icon>
            <input id="autoInput" class="inputClass" inputmode="none" type="number" v-model="inputCode" ref="input"
                autofocus @keyup.enter="inputFocus()">
        </van-popup>
    </div>
</body>

<script type="text/javascript">
    var vm;
    apiready = function () {

        api.addEventListener({
            name: 'selectRow'
        }, function (ret, err) {
            var type = ret.value.type;
            var row = ret.value.row;
            if (type == '机台') {
                vm.formData.EquipmentName = row.EquipmentName;
                vm.formData.EquipmentID = row.EquipmentID;

                api.sendEvent({
                    name: 'refreshDeviceRepair',
                    extra: {
                        change: vm.formData
                    }
                })
                api.sendEvent({
                    name: 'refreshBrowser',
                    extra: {
                        breadData: {
                            name: '设备维修明细',
                            url: 'deviceRepairDetail',
                            ZS_FunctionID: 0,
                            click: true
                        }
                    }
                })
                api.closeFrame()
            }
        })

        vm = new Vue({
            el: '#app',
            data: {
                formData: {
                    BillNO: '',
                    EquipmentName: '',
                    EquipmentID: '',
                    repairName: '',
                    repairID: '',
                    WXStartTime: '',
                    BXContent: '',
                    Reason: '',
                    GZCause: '',
                    DesRepContent: ''
                },
                tableData: [],
                scanShow: false,
                inputCode: '',
                PeriodType: [],
            },
            created: function () {
                var that = this;

                if (window.localStorage.getItem('clientHeight') != 752) {
                    document.getElementById('app').style.zoom = 0
                } else {
                    document.getElementById('app').style.zoom = 1.5
                }

                console.log('pageParam', JSON.stringify(api.pageParam.historyData))

                APP.ajax('MaintainEQ_Head_Form_ZS', { MaintainEquipmentID: api.pageParam.historyData.MaintainEquipmentID }, function (res) {
                    console.log('res', JSON.stringify(res))
                    that.formData.BillNO = res.ds[0].BillNO
                    that.formData.EquipmentName = res.ds[0].EquipmentName
                    that.formData.EquipmentID = res.ds[0].EquipmentID
                    that.formData.repairPin = res.ds[0].EmplID
                    that.formData.repairName = res.ds[0].EmplName
                    that.formData.WXStartTime = res.ds[0].WXStartTime.split('.')[0].replace('T', ' ')
                    that.formData.BXContent = res.ds[0].BXContent
                })
            },
            methods: {
                onClickLeft() {
                    api.closeFrame()
                },
                getTableData() {
                    var that = this
                    var obj = {
                        EquipmentID: that.formData.EquipmentID,
                        periodType: that.formData.unKeepTypeID
                    }
                    APP.ajax('getEQBYproject', obj, function (res) {
                        if (res.ds.length) {
                            console.log('res', JSON.stringify(res))
                            res.ds.map((item) => {
                                item.FResult = '1'
                            })
                            that.tableData = res.ds
                        } else {
                            that.tableData = []
                        }
                    })
                },
                confirmPeriod(value) {
                    var that = this
                    that.formData.unKeepType = value.name
                    that.formData.unKeepTypeID = value.periodType
                    that.getTableData()
                },
                openBaseScreen: function (str) {
                    var that = this;
                    var obj;
                    if (str == '机台') {
                        obj = {
                            allowClear: false,
                            showSearch: true,
                            searchKey: '',
                            serverSearch: false,
                            searchBy: ['EquipmentName'],
                            isPaging: false,
                            type: str,
                            cmd: 'getZSEquipment',
                            param: {
                            }
                        }
                    }

                    api.openWin({
                        name: 'baseScreen',
                        url: 'common/baseScreen.html',
                        reload: true,
                        slidBackEnabled: false,
                        pageParam: obj
                    })
                },
                inputFocus() {
                    var that = this
                    // console.log('that.inputCode', JSON.stringify(that.inputCode))
                    APP.ajax('ZS_CardLogin', { P_Card: that.inputCode }, function (res) {
                        // console.log('res', JSON.stringify(res))
                        if (res.ds[0].status == 200) {
                            that.formData.unKeepUserCode = res.ds[0].card_no
                            that.formData.unKeepUserName = res.ds[0].Name
                            vm.$toast(res.ds[0].msg);

                            APP.ajax('ZS_getEmplMessage', { Code: that.formData.unKeepUserCode }, function (res) {
                                that.formData.unKeepUserID = res.ds[0].EmplID
                            })
                            that.scanShow = false
                        } else {
                            vm.$toast(res.ds[0].msg);
                        }
                        that.inputCode = ''
                    })
                },
                confirmSub() {
                    var that = this
                    if (!that.formData.Reason) {
                        vm.$toast('请填写原因分析！');
                        return false;
                    }
                    if (!that.formData.GZCause) {
                        vm.$toast('请填写维修内容！');
                        return false;
                    }
                    var obj = {
                        MaintainEquipmentID: api.pageParam.historyData.MaintainEquipmentID,
                        GZCause: that.formData.GZCause,
                        DesRepContent: that.formData.DesRepContent,
                        Reason: that.formData.Reason
                    }
                    console.log('obj', JSON.stringify(obj))
                    APP.ajax('ZS_EQWXend', obj, function (res) {
                        console.log('res', JSON.stringify(res))
                        api.sendEvent({
                            name: 'refreshDeviceMantain'
                        })
                        vm.$toast('设备结束保养！');
                        api.sendEvent({
                            name: 'refreshBrowser',
                            extra: {
                                clearName: api.pageParam.name
                            }
                        })
                        api.closeFrame()
                    })
                },
            }
        })
    };
</script>

</html>